package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.AddAskInfoModel;

public class UserAddAskActivity extends BaseActivity {
    ImageView assask_fh;
    EditText assask_title,assask_content;
    TextView assask_btn;
    @Override
    void initView() {
        setLayout_file(R.layout.activity_user_add_ask);
        assask_fh = (ImageView)findViewById(R.id.assask_fh);
        assask_title = (EditText)findViewById(R.id.assask_title);
        assask_btn = (TextView)findViewById(R.id.assask_btn);
        assask_content = (EditText)findViewById(R.id.assask_content);
    }

    @Override
    void initEvent() {
        assask_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        assask_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String content = assask_content.getText().toString().trim();
                String title = assask_title.getText().toString().trim();
                if (content.equals("")||title.equals("")){
                    Toast.makeText(UserAddAskActivity.this,"提问信息不能出现空值",Toast.LENGTH_SHORT).show();
                }
                else {
                    AddAskInfoModel addAskInfoModel = new AddAskInfoModel();
                    addAskInfoModel.addAskInfo(getid(), title, content, new TListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            if (successBean.getSuccess().equals("1")){
                                Toast.makeText(UserAddAskActivity.this,"提问成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }
                            else {
                                Toast.makeText(UserAddAskActivity.this,"提问失败",Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void onFail(String msg) {
                            Toast.makeText(UserAddAskActivity.this,"提问失败？",Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }
        });

    }

    @Override
    void initDate() {

    }
}
